/**
 * Created with IntelliJ IDEA
 * Description:
 * User: Administrator
 * Data: 2023 - 08 - 12
 * Time: 13:47
 */
//力扣328 奇偶链表
class Solution2 {
    public ListNode oddEvenList(ListNode head) {
        if(head == null) return null;
        if(head.next == null) return head;
        ListNode oddCur = head;
        ListNode evenCur = head.next;
        ListNode th1 = head;
        ListNode th2 = head.next;
        while(th2 != null && th2.next != null) {//注意条件用&&，否则跳出循环后th1不指向奇数节点的最后一个节点
            th1.next = th2.next;
            th1 = th1.next;
            th2.next = th1.next;
            th2 = th2.next;
        }//跳出循环后th1指向奇数节点的最后一个节点
        th1.next = evenCur;
        return oddCur;
    }
}
